home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5593 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: pegasus.montclair.edu!harmon
  2. From: harmon@pegasus.montclair.edu (Derek Harmon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Solaris -> Windows & byte swapping
  5. Date: 15 Feb 1996 01:21:54 -0500
  6. Organization: Montclair State University
  7. Message-ID: <harmon.824364410@pegasus.montclair.edu>
  8. References: <4fsk3l$lab@due.unit.no>
  9. NNTP-Posting-Host: pegasus.montclair.edu
  10. X-Newsreader: NN version 6.5.0 #68 (NOV)
  11.  
  12. Vidar Moe <vidarm@ibt.unit.no> writes:
  13.  
  14. >I have transferred some binary datafiles from Solaris to my PC 
  15. >using ftp with the binary file transfer.
  16.  
  17.    The PC is certainly little-endian, whereas I can't know for certain
  18. what the Solaris machine is (endian-ism is an aspect of hardware platform),
  19. my experience with SPARCs has been big-endian, so as you suggest, you pro-
  20. bably have a conflict here.
  21.  
  22. >    fread(buffer, sizeof(unsigned char), dim, mImageFile);
  23.  
  24. >and then I process the bytes in the buffer further (my task is 
  25. >to convert a 12 bit image into an 8 bit image, and my problem 
  26. >is basically that the 12 bits belonging to each pixel is 
  27. >organized differently in the buffer under Windows than under 
  28. >Solaris!)
  29.  
  30.    It would help to read in more manageable chunks.  Say you want to convert
  31. from a 12-bit word to an 8-bit word, by reading in 8-bits at a time, you are
  32. loading either 1 1/2 or 2/3rds (depending on your perspective) at a time.
  33. The way to do this is by reading in a chunk size that's the least common
  34. factor.  For 8 and 12, that is 24.
  35.  
  36.    When you read in 24-bit chunks, you have 2 well-defined 12-bit words and
  37. in your case can more easily process these to be 2 well-defined 8-bit words.
  38. Take a 24-bit chunk-size, then process the first byte and high nybble of
  39. the second byte to become your first 8-bit word, and the low nybble of the
  40. second byte and third byte becomes your second 8-bit word.
  41.  
  42.                                                      -- Stone
  43. --
  44. # Derek Harmon (aka Stonelight)    harmon@pegasus.montclair.edu
  45. # - Computer Science Undergrad, Montclair State University, NJ
  46. # - My views are my own, nobody else is this creative.  3;)>
  47. ... "There is no reason anyone would want a computer in their home." - DEC '77
  48.  
  49.